﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Kokomo.Mirror.CliMetadata;

namespace Kokomo.PeInspector.Reflection.Disassembly
{
	public abstract class MsilMemberDependency : MsilDependency
	{
		protected MsilMemberDependency(
			Module targetModule,
			int metadataToken,
			int offset
			)
			: base(targetModule, offset)
		{
			this.MetadataToken = metadataToken;
		}

		public int MetadataToken { get; private set; }

		public MemberInfo GetMemberDependency()
		{
			return this.TargetModule.ResolveMember(this.MetadataToken);
		}

		public bool Matches(MemberInfo member)
		{
			if (member == null) throw new ArgumentNullException("member");

			return (this.TargetModule == member.Module) && (this.MetadataToken == member.MetadataToken);
		}

		public bool Matches(ModuleMemberReference member)
		{
			if (ModuleMemberReference.IsEmpty(member)) throw new ArgumentNullException("member");

			return (this.TargetModule == member.Module) && (this.MetadataToken == member.MetadataToken);
		}
	}
}
